package com.teaching.entity;

public class Teacher {
	private Integer teacherID;
	private String name;
	private Integer gender;
	private String university;
	private Integer course;
	private Integer grade;
	private Integer age;
	private Integer experience;
	private Integer sold;
	private Integer fee;
	private String address;
	private boolean degree;
	private boolean qualification;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getGender() {
		return gender;
	}
	public Integer getTeacherID() {
		return teacherID;
	}
	public void setTeacherID(Integer teacherID) {
		this.teacherID = teacherID;
	}
	public void setGender(Integer gender) {
		this.gender = gender;
	}
	public String getUniversity() {
		return university;
	}
	public void setUniversity(String university) {
		this.university = university;
	}
	public Integer getCourse() {
		return course;
	}
	public void setCourse(Integer course) {
		this.course = course;
	}
	public Integer getGrade() {
		return grade;
	}
	public void setGrade(Integer grade) {
		this.grade = grade;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public Integer getExperience() {
		return experience;
	}
	public void setExperience(Integer experience) {
		this.experience = experience;
	}
	public Integer getSold() {
		return sold;
	}
	public void setSold(Integer sold) {
		this.sold = sold;
	}
	public Integer getFee() {
		return fee;
	}
	public void setFee(Integer fee) {
		this.fee = fee;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public boolean isDegree() {
		return degree;
	}
	public void setDegree(boolean degree) {
		this.degree = degree;
	}
	public boolean isQualification() {
		return qualification;
	}
	public void setQualification(boolean qualification) {
		this.qualification = qualification;
	}
	
	// 构造函数，创建一个新的teacher类
	public Teacher(String name, Integer gender, String university, Integer course, Integer grade, Integer age,
			 Integer fee, String address) {
		// 父类的构造函数，初始化父类，如果父类是Object，有没有都可以。其他情况，应该带上
		super(); 
		this.name = name;
		this.gender = gender;
		this.university = university;
		this.course = course;
		this.grade = grade;
		this.age = age;
		this.experience = 0;
		this.sold = 0;
		this.fee = fee;
		this.address = address;
		this.degree = false;
		this.qualification = false;
		this.teacherID=hashCode();
	}
	public Teacher() {
		super();
	}
	// 构造函数，创建一个新的teacher类
	public Teacher(String name, Integer gender, String university, Integer course, Integer grade) {
		super();
		this.name = name;
		this.gender = gender;
		this.university = university;
		this.course = course;
		this.grade = grade;
		this.age = 20;
		this.experience = 0;
		this.sold = 0;
		this.fee = 200;
		this.address = "Not known";
		this.degree = false;
		this.qualification = false;
		this.teacherID=hashCode();
	}
	
	@Override
	public String toString() {
		return "Teacher [teacherID=" + teacherID + ", name=" + name + ", gender=" + gender + ", university="
				+ university + ", course=" + course + ", grade=" + grade + ", age=" + age + ", experience=" + experience
				+ ", sold=" + sold + ", fee=" + fee + ", address=" + address + ", degree=" + degree + ", qualification="
				+ qualification + "]";
	}
	// 哈希函数，就是把一些东西映射成一个数字的，具体没啥，就是生成个人ID的时候比较好用
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result + ((course == null) ? 0 : course.hashCode());
		result = prime * result + ((gender == null) ? 0 : gender.hashCode());
		result = prime * result + ((grade == null) ? 0 : grade.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((university == null) ? 0 : university.hashCode());
		return result;
	}
	// 哈希和相等时一致的，就是。
	// 下面的相等函数直接比较对象的属性，我们也可以直接比较哈希值。哈希就是一个映射关系，就是一个散列函数
	// 比如y=x就是一个哈希函数。y=2x也行，但是y=x*x就不能做哈希函数，因为正数负数平方值会相等。
	// 哈希函数目的就是提供一个一对一的映射,有且只有一个y值与任意输入对应，且保证不同输入，y一定不同
	// 仅仅是说，现在的
	// 哈希函数 = 类似于身份证号！类似于护照号！对，就这么简单的一个东西！懂了吗？
	// 输入：任意的东西，string也好，integer也好，float也好，boolean等等都能做哈希，
	// 输出：产生一个惟一的数字
	// 用途：1, 如果哈希结果相等，那么两个对象就是一样的. 2, 做标志符，是惟一的识别码
	// 为什么用哈希？因为要比较的对象内容比较多，你要比较相等，只能一项一项去比较，很慢，
	// 或者说，写程序比较烦人，你要清楚地知道对象类型,具体有什么属性，对象是否为空，等等。用哈希的话，只需要比较哈希值是否相等
	// 你看下面的函数，一项一项比较，而且必须首先判断出两个数字都不是null，然后才能比。你用哈希，就只需要比较哈希值是否相等
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Teacher other = (Teacher) obj;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (course == null) {
			if (other.course != null)
				return false;
		} else if (!course.equals(other.course))
			return false;
		if (gender == null) {
			if (other.gender != null)
				return false;
		} else if (!gender.equals(other.gender))
			return false;
		if (grade == null) {
			if (other.grade != null)
				return false;
		} else if (!grade.equals(other.grade))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (university == null) {
			if (other.university != null)
				return false;
		} else if (!university.equals(other.university))
			return false;
		return true;
	}
	
	public boolean findByCourse(Integer course, Integer grade) {
		if ((this.course==course) &&(this.grade==grade)) {
			return true;
		}
		else {
			return false;
		}
	}
	
	
	
	

}
